package com.loukou.lkt.cron.task;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.loukou.lkt.lkt.dao.PoPurchaseReturnOrderDao;
import com.loukou.lkt.lkt.entity.PoPurchaseReturnOrder;
import com.loukou.lkt.lkt.enums.PoPurchaseReturnOrderStateEnum;
import com.loukou.lkt.lkt.resp.RespDto;
import com.loukou.lkt.lkt.service.PoPurchaseReturnOrderService;

@Service("SendPurchaseReturnStockOutOrderTask")
public class SendPurchaseReturnStockOutOrderTask{
	Logger logger = Logger.getLogger(SendPurchaseStockInOrderTask.class);
	
	@Autowired
	private PoPurchaseReturnOrderDao poReturnDao;
	
	@Autowired
	private PoPurchaseReturnOrderService poPurchaseReturnOrderService;
	
	public void noticeWmsOut() {
		List<PoPurchaseReturnOrder> orderList=poReturnDao.findByOrderState(PoPurchaseReturnOrderStateEnum.STATE_FINANCE_PASS.getState());
		
		if(orderList!=null && orderList.size()>0){
			for(PoPurchaseReturnOrder o:orderList){
				RespDto<String> result=poPurchaseReturnOrderService.sendPurchaseReturnOrderToWms(o.getId());
				if (result.getCode()!=200) {
					logger.error("send purchase return order error!");
					logger.error("推送退货单id【" + o.getId() + "】失败，错误:"
							+ result.getMsg());
					continue;
				}
			}
		}
	}
}
